/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.ComboBox
 *  javafx.scene.layout.AnchorPane
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.SaleScheduleSettingUtil;
import com.gys.common.business.SalesReceiptsUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.data.KeyValue;
import com.gys.common.util.CommonUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.data.example.GetUserOutData;
import com.gys.data.salesReceipts.GaiaStoreData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.AnchorPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class ReplaceSaleController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(ReplaceSaleController.class);
    @FXML
    private ComboBox<KeyValue> shop;
    @FXML
    private ComboBox<KeyValue> emp;
    @FXML
    private AnchorPane pane;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        CommonUtil.comboxInit(this.shop);
        CommonUtil.comboxInit(this.emp);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.shop.setValue(new KeyValue());
        this.emp.setValue(new KeyValue());
        GetUserOutData loginUser = this.getLoginUser();
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("client", loginUser.getClient());
        param.put("depId", loginUser.getDepId());
        HttpJson httpJson = SalesReceiptsUtil.otherShops(param);
        List<GaiaStoreData> storeDataList = null;
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        storeDataList = JSON.parseArray((String)httpJson.getMsg(), GaiaStoreData.class);
        ArrayList keyValueList = new ArrayList();
        if (ObjectUtil.isNotEmpty(storeDataList)) {
            storeDataList.forEach(item -> {
                KeyValue keyValue = new KeyValue();
                keyValue.setName(item.getStoName());
                keyValue.setValue(item.getStoCode());
                keyValueList.add(keyValue);
            });
        }
        ObservableList options = FXCollections.observableArrayList(keyValueList);
        this.shop.setItems(options);
    }

    @FXML
    private void selectShop() {
        if (ObjectUtil.isEmpty(this.shop.getValue()) || ObjectUtil.isEmpty(((KeyValue)this.shop.getValue()).getValue())) {
            return;
        }
        this.emp.setItems(FXCollections.observableArrayList());
        this.emp.setValue(new KeyValue());
        String shopId = ((KeyValue)this.shop.getValue()).getValue();
        GetUserOutData loginUser = this.getLoginUser();
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("clientId", loginUser.getClient());
        param.put("gsegBrId", shopId);
        HttpJson httpJson = SaleScheduleSettingUtil.queryUser(param);
        List<GetUserOutData> userOutDataList = null;
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        userOutDataList = JSON.parseArray((String)httpJson.getMsg(), GetUserOutData.class);
        ArrayList keyValueList = new ArrayList();
        if (ObjectUtil.isNotEmpty(userOutDataList)) {
            userOutDataList.forEach(item -> {
                KeyValue keyValue = new KeyValue();
                keyValue.setName(item.getLoginName());
                keyValue.setValue(item.getUserId());
                keyValueList.add(keyValue);
            });
        }
        ObservableList options = FXCollections.observableArrayList(keyValueList);
        this.emp.setItems(options);
    }

    @FXML
    private void sureAction() {
        if (ObjectUtil.isEmpty(((KeyValue)this.emp.getValue()).getValue())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u9009\u62e9\u95e8\u5e97\u4eba\u5458");
            alert.showAndWait();
            return;
        }
        this.salesReceiptsMainController.setReplaceUserId(((KeyValue)this.emp.getValue()).getValue());
        this.salesReceiptsMainController.setDeptId(((KeyValue)this.shop.getValue()).getValue());
        this.cancelAction();
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }
}

